package com.matea.order.utils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * Created by 廖师兄
 * 2018-02-21 10:40
 */
public class JsonUtil {

	private static ObjectMapper objectMapper = new ObjectMapper();

	/**
	 * json转换为对象
	 */
	public static Object fromJson(String string,Class classType){
		try {
			return objectMapper.readValue(string,classType);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * json转换为对象
	 */
	public static Object fromJson(String string,TypeReference typeReference){
		try {
			return objectMapper.readValue(string,typeReference);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}